/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package control.benhan;

import com.toedter.calendar.JDateChooser;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import model.dao.benhan.BenhAnDAO;
import model.entity.Benh;
import model.entity.BenhAn;

/**
 *
 * @author Admin
 */
public class BASuaThongTin_Full_Ctrl {
    
    public static final void lietKetheoMaBA(JTextField tfMaBA, JTable table){
        int maBA = Integer.parseInt(tfMaBA.getText());
        
        List list = BenhAnDAO.loadBenhAnTheoMaBenhAn(maBA);
        
        Vector<String>tableHeader = new Vector<String>();
        tableHeader.add("Mã BA");
        tableHeader.add("Tên Bệnh");
        tableHeader.add("Ngày Bắt Đầu");
        tableHeader.add("Ngày Kết Thúc");
        tableHeader.add("Trạng Thái");
        tableHeader.add("Ghi Chú");
        
        Vector data = new Vector();
        for (Object object : list) {
            BenhAn benhAn = (BenhAn)object;
            Vector<Object>oneRow = new Vector<Object>();
            oneRow.add(benhAn.getBaMa());
            oneRow.add(benhAn.getBenh().getBenhTen());
            oneRow.add(benhAn.getBaNgayBd());
            oneRow.add(benhAn.getBaNgayKt());
            oneRow.add(benhAn.getBaTrangThai());
            oneRow.add(benhAn.getBaGhiChu());
            
            data.add(oneRow);
        }
        table.setModel(new DefaultTableModel(data, tableHeader));
    }
    
    /**
     * Liệt Kê theo tên Bệnh
     */
    public static final void lietKeTheoTenBA(JTextField tfTen, JTable table){
        String tenB = tfTen.getText();
        List list = BenhAnDAO.loadBenhAnTheoTenBenh(tenB);
         Vector<String>tableHeader = new Vector<String>();
        tableHeader.add("Mã BA");
        tableHeader.add("Tên Bệnh");
        tableHeader.add("Ngày Bắt Đầu");
        tableHeader.add("Ngày Kết Thúc");
        tableHeader.add("Trạng Thái");
        tableHeader.add("Ghi Chú");
        

        
        Vector data = new Vector();
        for (Object object : list) {
            BenhAn benhAn = (BenhAn)object;
            
            Vector<Object>oneRow = new Vector<Object>();
            oneRow.add(benhAn.getBaMa());
            oneRow.add(benhAn.getBenh().getBenhTen());
            oneRow.add(benhAn.getBaNgayBd());
            oneRow.add(benhAn.getBaNgayKt());
            oneRow.add(benhAn.getBaTrangThai());
            oneRow.add(benhAn.getBaGhiChu());
            
            data.add(oneRow);
        }
        
        table.setModel(new DefaultTableModel(data, tableHeader));
        
    }
    
    public static final BenhAn selectRow(JTable table){
        int row = table.getSelectedRow();
        
        int maBA = (Integer)table.getValueAt(row, 0);
        String tenBenh = (String)table.getValueAt(row, 1);
        Date ngayBD = (Date)table.getValueAt(row, 2);
        Date ngayKT = (Date)table.getValueAt(row, 3);
        String trangThai = (String)table.getValueAt(row, 4);
        String ghiChu = (String)table.getValueAt(row, 5);
        
        BenhAn benhAn = new BenhAn();
        Benh benh = new Benh();
        benh.setBenhTen(tenBenh);
        benhAn.setBaMa(maBA);
        benhAn.setBenh(benh);
         benhAn.setBaNgayBd(ngayBD);
        benhAn.setBaNgayKt(ngayKT);
        benhAn.setBaTrangThai(trangThai);
        benhAn.setBaGhiChu(ghiChu);
        
        return benhAn;
        
    }
}
